package com.newcoder.alibaba;


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Mock004{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[][] input = new int[n][k];
        for(int i=0; i<n; i++){
            for(int j=0; j<k; j++){
                input[i][j] = scan.nextInt();
            }
        }
        int res = getAns(input, n, k);
        System.out.println(res);
    }

    public static int getAns(int[][] input, int n, int k){
        int count = 0;
        Map<String, Integer> map = new HashMap<>();
        for(int i=0; i<n; i++){
            String s = transferToString(input[i]);
            String reverse = reverseString(input[i]);
            if(map.containsKey(s)){
                count += map.get(s);
            }
            map.put(reverse, map.getOrDefault(reverse, 0)+1);
        }
        return count;
    }

    public static String transferToString(int[] arr){
        StringBuilder sb = new StringBuilder("0");
        for(int i=1; i<arr.length; i++){
            if(arr[i]-arr[0] > 0){
                sb.append("+");
                sb.append(arr[i]-arr[0]);
            }else if(arr[i]-arr[0] < 0) {
                sb.append(arr[i]-arr[0]);
            }else {
                sb.append(0);
            }
        }
        return sb.toString();
    }

    public static String reverseString(int[] arr){
        StringBuilder sb = new StringBuilder("0");
        for(int i=1; i<arr.length; i++){
            if(arr[i]-arr[0] > 0){
                sb.append("-");
                sb.append(arr[i]-arr[0]);
            }else if(arr[i]-arr[0] < 0) {
                sb.append("+");
                sb.append(arr[0]-arr[i]);
            }else {
                sb.append(0);
            }
        }
        return sb.toString();
    }
}

